#pragma once
#include <memory>
#include <vector>
#include "rtdev/rtdev.h"

namespace rtdev {

typedef enum
{
    BP_STATUS_R = 0x191,
    BP_STATUS_W = 0x211,
} BpFuncCode;

enum class BpColor : uint8_t
{
    BP_RGB_OFF = 0,
    BP_RGB_RED = 1,
    BP_RGB_GREEN = 2,
    BP_RGB_BLUE = 3,
    BP_RGB_WHITE = 4,
    BP_RGB_YELLOW = 5,
    BP_RGB_FUCHSIA = 6,
    BP_RGB_CYAN = 7
};

// 手柄状态
typedef struct
{
    BpColor bp_rgb_lock_color;
    uint8_t bp_rgb_lock_brightness;  // 范围0-100
    BpColor bp_rgb_logol_color;
    uint8_t bp_rgb_logol_brightness;  // 范围0-100
    uint8_t bp_beep;
    uint8_t heartbeat;
    uint8_t key_buffer;
    uint8_t reserve_1;
    uint8_t reserve_2;
} BpStatus;

class JkBpItf
{
public:
    JkBpItf();
    ~JkBpItf() = default;
    int get_id();
    int set_id(uint32_t id);
    int set_bp_logo_color(BpColor color);
    int set_bp_logo_brightness(uint8_t data);
    int set_bp_lock_color(BpColor color);
    int set_bp_lock_brightness(uint8_t data);
    int set_bp_beep(uint8_t data);
    BpStatus bp_status_;
    BpStatus bp_cmd_;
    int32_t bp_id;
};

class ButtonPanelItf : public rtdev::RtDevItf
{
public:
    ButtonPanelItf();
    ~ButtonPanelItf() = default;
    const char* name() { return "JK_BP"; }
    int init(const char* cfgfile = nullptr);
    int boot();
    int shutdown() { return 0; }
    void check_alive();
    int keep_alive(int alive);
    bool is_alive();
    bool is_sim();

public:
    int set_send_data(int busid = -1);
    int get_recv_data(int busid = -1);
    std::shared_ptr<rtbus::RtCommuItf> bus_;

protected:
    uint8_t sim_flag_;
    int alive_watchdog_;
    bool alive_flag_;
    int last_alive_cnt_;
    int bus_id_;

public:
    JkBpItf* bp() { return &bp_; }

private:
    JkBpItf bp_;
};

}  // namespace rtdev